<?php

/**
 * This is the model class for table "md_western_medicine".
 *
 * The followings are the available columns in table 'md_western_medicine':
 * @property string $pk_medicine_id
 * @property string $category_guid
 * @property string $class_first
 * @property string $class_second
 * @property string $class_third
 * @property string $product_category
 * @property string $product_name_ch
 * @property string $product_name_ch_ab
 * @property string $product_name_en
 * @property string $common_name_ch
 * @property string $common_name_ch_ab
 * @property string $common_name_en
 * @property string $chemical_name
 * @property string $dosage
 * @property string $brand
 * @property string $specification
 * @property string $package_specification
 * @property string $drug_level
 * @property string $unit
 * @property string $efficacy
 * @property string $usages
 * @property string $pharmaco
 * @property string $ingredient
 * @property string $side_effect
 * @property string $note
 * @property string $taboo
 * @property string $storage
 * @property string $interaction
 * @property integer $attribute
 * @property string $good_for
 * @property string $characters
 * @property double $price
 * @property double $vip_price
 * @property string $approval_number
 * @property string $original_approval_number
 * @property string $approval_number_remark
 * @property string $repackage_approval_number
 * @property string $manufacturer_ch
 * @property string $manufacturer_en
 * @property string $manufacturer_country_ch
 * @property string $manufacturer_country_en
 * @property string $manufacturer_address_ch
 * @property string $manufacturer_address_en
 * @property string $bar_code
 * @property integer $is_import
 * @property string $certificate_date
 * @property string $expiry_date
 * @property string $drug_standard_code
 * @property string $drug_standard_code_remark
 * @property string $repackage_company_name
 * @property string $repackage_company_address
 * @property string $repackage_approval_date
 * @property string $repackage_approval_expiry_date
 * @property string $remark
 * @property string $inventory
 * @property string $create_time
 * @property string $update_time
 */
class MdWesternMedicine extends CActiveRecord
{
	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'md_western_medicine';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('attribute, is_import', 'numerical', 'integerOnly'=>true),
			array('price, vip_price', 'numerical'),
			array('category_guid', 'length', 'max'=>32),
			array('class_first, class_second, class_third, product_category, product_name_ch_ab, common_name_ch_ab', 'length', 'max'=>50),
			array('product_name_ch, product_name_en, common_name_ch, common_name_en, chemical_name, dosage, brand, specification, package_specification, storage, good_for, characters, approval_number, original_approval_number, approval_number_remark, repackage_approval_number, manufacturer_ch, manufacturer_en, manufacturer_country_ch, manufacturer_country_en, manufacturer_address_ch, manufacturer_address_en, bar_code, certificate_date, drug_standard_code_remark, repackage_company_name, repackage_company_address', 'length', 'max'=>300),
			array('unit, expiry_date', 'length', 'max'=>100),
			array('ingredient', 'length', 'max'=>800),
			array('drug_standard_code', 'length', 'max'=>500),
			array('inventory', 'length', 'max'=>20),
			array('drug_level, efficacy, usages, pharmaco, side_effect, note, taboo, interaction, repackage_approval_date, repackage_approval_expiry_date, remark, create_time, update_time', 'safe'),
			// The following rule is used by search().
			// @todo Please remove those attributes that should not be searched.
			array('pk_medicine_id, category_guid, class_first, class_second, class_third, product_category, product_name_ch, product_name_ch_ab, product_name_en, common_name_ch, common_name_ch_ab, common_name_en, chemical_name, dosage, brand, specification, package_specification, drug_level, unit, efficacy, usages, pharmaco, ingredient, side_effect, note, taboo, storage, interaction, attribute, good_for, characters, price, vip_price, approval_number, original_approval_number, approval_number_remark, repackage_approval_number, manufacturer_ch, manufacturer_en, manufacturer_country_ch, manufacturer_country_en, manufacturer_address_ch, manufacturer_address_en, bar_code, is_import, certificate_date, expiry_date, drug_standard_code, drug_standard_code_remark, repackage_company_name, repackage_company_address, repackage_approval_date, repackage_approval_expiry_date, remark, inventory, create_time, update_time', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'pk_medicine_id' => 'Pk Medicine',
			'category_guid' => 'Category Guid',
			'class_first' => 'Class First',
			'class_second' => 'Class Second',
			'class_third' => 'Class Third',
			'product_category' => 'Product Category',
			'product_name_ch' => 'Product Name Ch',
			'product_name_ch_ab' => 'Product Name Ch Ab',
			'product_name_en' => 'Product Name En',
			'common_name_ch' => 'Common Name Ch',
			'common_name_ch_ab' => 'Common Name Ch Ab',
			'common_name_en' => 'Common Name En',
			'chemical_name' => 'Chemical Name',
			'dosage' => 'Dosage',
			'brand' => 'Brand',
			'specification' => 'Specification',
			'package_specification' => 'Package Specification',
			'drug_level' => 'Drug Level',
			'unit' => 'Unit',
			'efficacy' => 'Efficacy',
			'usages' => 'Usages',
			'pharmaco' => 'Pharmaco',
			'ingredient' => 'Ingredient',
			'side_effect' => 'Side Effect',
			'note' => 'Note',
			'taboo' => 'Taboo',
			'storage' => 'Storage',
			'interaction' => 'Interaction',
			'attribute' => 'Attribute',
			'good_for' => 'Good For',
			'characters' => 'Characters',
			'price' => 'Price',
			'vip_price' => 'Vip Price',
			'approval_number' => 'Approval Number',
			'original_approval_number' => 'Original Approval Number',
			'approval_number_remark' => 'Approval Number Remark',
			'repackage_approval_number' => 'Repackage Approval Number',
			'manufacturer_ch' => 'Manufacturer Ch',
			'manufacturer_en' => 'Manufacturer En',
			'manufacturer_country_ch' => 'Manufacturer Country Ch',
			'manufacturer_country_en' => 'Manufacturer Country En',
			'manufacturer_address_ch' => 'Manufacturer Address Ch',
			'manufacturer_address_en' => 'Manufacturer Address En',
			'bar_code' => 'Bar Code',
			'is_import' => 'Is Import',
			'certificate_date' => 'Certificate Date',
			'expiry_date' => 'Expiry Date',
			'drug_standard_code' => 'Drug Standard Code',
			'drug_standard_code_remark' => 'Drug Standard Code Remark',
			'repackage_company_name' => 'Repackage Company Name',
			'repackage_company_address' => 'Repackage Company Address',
			'repackage_approval_date' => 'Repackage Approval Date',
			'repackage_approval_expiry_date' => 'Repackage Approval Expiry Date',
			'remark' => 'Remark',
			'inventory' => 'Inventory',
			'create_time' => 'Create Time',
			'update_time' => 'Update Time',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 *
	 * Typical usecase:
	 * - Initialize the model fields with values from filter form.
	 * - Execute this method to get CActiveDataProvider instance which will filter
	 * models according to data in model fields.
	 * - Pass data provider to CGridView, CListView or any similar widget.
	 *
	 * @return CActiveDataProvider the data provider that can return the models
	 * based on the search/filter conditions.
	 */
	public function search()
	{
		// @todo Please modify the following code to remove attributes that should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('pk_medicine_id',$this->pk_medicine_id,true);
		$criteria->compare('category_guid',$this->category_guid,true);
		$criteria->compare('class_first',$this->class_first,true);
		$criteria->compare('class_second',$this->class_second,true);
		$criteria->compare('class_third',$this->class_third,true);
		$criteria->compare('product_category',$this->product_category,true);
		$criteria->compare('product_name_ch',$this->product_name_ch,true);
		$criteria->compare('product_name_ch_ab',$this->product_name_ch_ab,true);
		$criteria->compare('product_name_en',$this->product_name_en,true);
		$criteria->compare('common_name_ch',$this->common_name_ch,true);
		$criteria->compare('common_name_ch_ab',$this->common_name_ch_ab,true);
		$criteria->compare('common_name_en',$this->common_name_en,true);
		$criteria->compare('chemical_name',$this->chemical_name,true);
		$criteria->compare('dosage',$this->dosage,true);
		$criteria->compare('brand',$this->brand,true);
		$criteria->compare('specification',$this->specification,true);
		$criteria->compare('package_specification',$this->package_specification,true);
		$criteria->compare('drug_level',$this->drug_level,true);
		$criteria->compare('unit',$this->unit,true);
		$criteria->compare('efficacy',$this->efficacy,true);
		$criteria->compare('usages',$this->usages,true);
		$criteria->compare('pharmaco',$this->pharmaco,true);
		$criteria->compare('ingredient',$this->ingredient,true);
		$criteria->compare('side_effect',$this->side_effect,true);
		$criteria->compare('note',$this->note,true);
		$criteria->compare('taboo',$this->taboo,true);
		$criteria->compare('storage',$this->storage,true);
		$criteria->compare('interaction',$this->interaction,true);
		$criteria->compare('attribute',$this->attribute);
		$criteria->compare('good_for',$this->good_for,true);
		$criteria->compare('characters',$this->characters,true);
		$criteria->compare('price',$this->price);
		$criteria->compare('vip_price',$this->vip_price);
		$criteria->compare('approval_number',$this->approval_number,true);
		$criteria->compare('original_approval_number',$this->original_approval_number,true);
		$criteria->compare('approval_number_remark',$this->approval_number_remark,true);
		$criteria->compare('repackage_approval_number',$this->repackage_approval_number,true);
		$criteria->compare('manufacturer_ch',$this->manufacturer_ch,true);
		$criteria->compare('manufacturer_en',$this->manufacturer_en,true);
		$criteria->compare('manufacturer_country_ch',$this->manufacturer_country_ch,true);
		$criteria->compare('manufacturer_country_en',$this->manufacturer_country_en,true);
		$criteria->compare('manufacturer_address_ch',$this->manufacturer_address_ch,true);
		$criteria->compare('manufacturer_address_en',$this->manufacturer_address_en,true);
		$criteria->compare('bar_code',$this->bar_code,true);
		$criteria->compare('is_import',$this->is_import);
		$criteria->compare('certificate_date',$this->certificate_date,true);
		$criteria->compare('expiry_date',$this->expiry_date,true);
		$criteria->compare('drug_standard_code',$this->drug_standard_code,true);
		$criteria->compare('drug_standard_code_remark',$this->drug_standard_code_remark,true);
		$criteria->compare('repackage_company_name',$this->repackage_company_name,true);
		$criteria->compare('repackage_company_address',$this->repackage_company_address,true);
		$criteria->compare('repackage_approval_date',$this->repackage_approval_date,true);
		$criteria->compare('repackage_approval_expiry_date',$this->repackage_approval_expiry_date,true);
		$criteria->compare('remark',$this->remark,true);
		$criteria->compare('inventory',$this->inventory,true);
		$criteria->compare('create_time',$this->create_time,true);
		$criteria->compare('update_time',$this->update_time,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}

	public function getDbConnection()
	{
		return Yii::app()->medicinedb;
	}

	/**
	 * Returns the static model of the specified AR class.
	 * Please note that you should have this exact method in all your CActiveRecord descendants!
	 * @param string $className active record class name.
	 * @return MdWesternMedicine the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}
}
